package com.jd.sunny.util;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import java.io.IOException;
import java.util.Properties;

/**
 * @author :孙林
 * @ClassName:LogUtil
 * @Description: 日志工具类(完成)
 * @date :2012-8-22下午2:56:13
 */

public class LogUtil {

    //此处不能用ConfigUtil，因为其中也使用了LogUtil，调用就会初始化，但是此时还没加载log4j的配置文件
//	private static String configFilename = ConfigUtil.getDefaultProperty("log4j");

    private static String configFilename = "config_develop/log4j.properties";
    private static final Logger logger = Logger.getLogger(LogUtil.class);

    private LogUtil() {
    }

    /**
     * 获取日志
     *
     * @return
     */
    public static Logger getLogger() {
        //读取指定的配置文件
        Properties properties = new Properties();
        try {
            properties.load(LogUtil.class.getClassLoader().getResourceAsStream(configFilename));
            PropertyConfigurator.configure(properties);
//            PropertyConfigurator.configure(configFilename);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return logger;
    }

}
